/**
 * Provides the FirstLight InventoryState example in the GQE library.
 *
 * @file examples/demo/InventoryState.cpp
 * @author jacob Dix
 * @date 20110704 - Initial Release
 * @date 20110721 - Remove * from GetAsset() calls since it now returns TYPE&
 * @date 20110831 - Support new SFML2 snapshot changes
 */
#include "States/InventoryState.hpp"
#include "States/GameState.hpp"
#include <GQE/Core/assets/ImageAsset.hpp>
#include <GQE/Core/classes/App.hpp>
#include "Objects/ButtonObject.hpp"
#include "classes/ContentManager.hpp"
#include "classes/Command.hpp"
#include "classes/PlayerClass.hpp"
#include "classes/GUIClass.hpp"
#include "Game_types.hpp"
InventoryState::InventoryState(GQE::App* theApp) :
    GQE::IState("Game",theApp),
    mInventory(NULL),
	mConsole(6,40)
{
}

InventoryState::~InventoryState(void)
{
}

void InventoryState::DoInit(void)
{
    // First call our base class implementation
    IState::DoInit();

    // Check our App pointer
    assert(NULL != mApp && "InventoryState::DoInit() bad app pointer");
    int anItemIndex=0;
    int anX=32;
    int anY=32;
    //Set up inventory controls
    GUIClass::MakeItemList(mApp,&mObjectManager,gPlayer->GetInventory());
    GUIClass::MakeButton(mApp,&mObjectManager,"Back","Exit",32,432);
	sf::String anNewString;
	anNewString.SetFont(mApp->mAssetManager.GetFont("MainFont")->GetAsset());
    anNewString.SetText("");
    anNewString.SetColor(sf::Color::Black);
    anNewString.SetSize(16);
    unsigned int anLine;
    for(anLine=0; anLine<6; anLine++)
    {
        anNewString.SetPosition(200,400-16*anLine);
        mMainStrings.push_back(anNewString);
    }
	gMainWindow=&mConsole;
}

void InventoryState::ReInit(void)
{

}

void InventoryState::HandleEvents(sf::Event theEvent)
{
    if(theEvent.Type==sf::Event::KeyPressed)
    {

    }
}

void InventoryState::UpdateFixed(void)
{
    const sf::Input& Input=mApp->mWindow.GetInput();
	unsigned int anLine;
    unsigned int anLineCount=6;
    for(anLine=0; anLine<anLineCount; ++anLine)
    {
		mMainStrings[anLine].SetText(mConsole.GetLine(mConsole.mLineNum-anLine-1));
    }
    mObjectManager.UpdateFixed();
}

void InventoryState::UpdateVariable(float theElapsedTime)
{
    mObjectManager.UpdateVariable(theElapsedTime);
}

void InventoryState::Draw(void)
{
    mObjectManager.UpdateLists();
    mApp->mWindow.Clear(sf::Color(255,255,255));
    mObjectManager.Draw();
    std::vector<sf::String>::iterator anIter;
    for(anIter=mMainStrings.begin(); anIter!=mMainStrings.end(); anIter++)
    {
        mApp->mWindow.Draw((*anIter));
    }
}

void InventoryState::Cleanup(void)
{
    mObjectManager.ClearObjects();
    gMainWindow=NULL;
    // Last of all, call our base class implementation
    IState::Cleanup();
}
